
import React, { Component } from 'react';
import { View, Platform, SafeAreaView } from 'react-native';
import constants from '../../utils/constants';
import MainWrong from './wrong/main';
import { createBottomTabNavigator, createAppContainer } from 'react-navigation';
import User from '../user';
import Find from '../find';
import Tabbar from './icon/tabbar';
import Utils from '../../utils';
import MaterialIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import { Toast } from 'antd-mobile-rn';
import StudyNew from './page/studyNew';
import MainHome from './page/main';
import Study from './page/study';





const TabNavigator = createBottomTabNavigator({
    MainHome: Study,
    MainWrong: MainWrong,
    Find: Find,
    UserCenter: User

}, {
        defaultNavigationOptions: ({ navigation }) => ({
            tabBarIcon: ({ focused, horizontal, tintColor }) => {
                const icons = {
                    "MainHome": "study",
                    "MainWrong": "ceshishenqing",
                    "Find": "discovery",
                    "UserCenter": "wode1"

                }
                if(navigation.state.routeName === "Find"){
                    return <MaterialIcons name={"lightbulb-on-outline"} size={horizontal ? 20 : 25} color={tintColor} />;
                }
                return <Tabbar name={icons[navigation.state.routeName]} size={horizontal ? 20 : 25} color={tintColor} />;
            },

        }),
        tabBarOptions: {
            activeTintColor: "#000000"
        },
        lazy: false,

    });


const TabApp = createAppContainer(TabNavigator);

export default class Home extends Component {



    static navigationOptions = (e) => {
        return {
            header: (e) => {
                return null; 

            }
        }
    }


    constructor(props) {
        super(props);
        this.navigation = this.props.navigation;
        this.state = {
            selectedTab: "home"
        }
    }

    componentDidMount() {

        //Toast.info(Platform.Version)

        const { navigate } = this.props.navigation;

        Utils.getLoginInfo().then(user => {
            if (!user) {
                navigate("Login");
                return;
            }

           
        });




    }



    render() {
        return (
            // <SafeAreaView style={{ flex: 1}}>
            
            // </SafeAreaView>
            <View style={{ flex: 1,paddingTop:Platform.OS === "android"?0: (parseFloat(Platform.Version) < 11?20:0)}}>
                 <TabApp screenProps={{ appNavigation: this.props.navigation}} />   
            </View>
        )
    }
}